package com.ego.e.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup

/**
 * 多种布局的Adapter
 * @see EAdapter
 * Created by lxy on 2017/5/21.
 */
abstract class AdapterX<Data>(context: Context, datas: MutableList<Data>) : EAdapter<Data>(context, datas) {

    override abstract fun getItemViewType(position: Int): Int

    abstract fun layout(viewType: Int): Int
    abstract fun bind(holder: EHolder, data: Data, position: Int, viewType: Int)

    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): EHolder {
        var layout = layout(viewType)
        return EHolder(LayoutInflater.from(context).inflate(layout, parent, false))
    }

    override fun onBindViewHolder(holder: EHolder, position: Int) {
        var viewType = getItemViewType(position)
        var data = datas!![position]
        bind(holder, data, position, viewType)
        onBindListener(holder.itemView, data, position)
    }
}